<!DOCTYPE html>
<html lang="zh-cn">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>数据库交互</title>
    <!-- Bootstrap -->
    <link href="bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">

  </head>
  <body>
  <h1>数据列表</h1>
  <form action= "c.php" method = "get">
  <button class="btn btn-lg btn-default" type="submit">添加</button>
    

<?php
header("content-type:text/html;charset=utf-8");

class db1{
	private $localhost = "localhost";
	private $name = "root";
	private $code = "root";
	private $database = "pro";
	private $con;


function connect(){
	$this->con = mysql_connect($this->localhost,$this->name,$this->code);
	mysql_select_db($this->database,$this->con);
	mysql_query("set names utf8");
}

function __construct(){
    $this->connect();
}

function __destruct(){
    mysql_close($this->con);
}

function myarray($result){
	while($tmp=mysql_fetch_array($result,MYSQL_ASSOC)){
	$list[] = $tmp;
	}
	return $list;
}

function select($table,$cd){
	return mysql_query("select * from $table $cd");
}
function insert($table,$fields,$value){
	 mysql_query("insert into $table $fields values $value");
}
function update($table,$change,$cd){
	mysql_query("update $table set $change where $cd");
}
function delete($table,$cd){
	mysql_query("delete from $table $cd");
}

}

$db = new db1();
//$db->update("product","title='yy'","title='ff'");
$select = $db->select("product","");
$list = $db->myarray($select);
?>


<table class="table table-bordered">
    <thead>
    <tr>
        <th>ID</th>
		<th>名称</th>
		<th>标题</th>
		<th>类型</th>
		<th>价格</th>
		<th>操作</th>
    </tr>
    </thead>
    <tbody>
    <?php foreach ($list as $k=>$v){?>
    <tr>
        <td><?php echo $v['id'];?></td>
        <td><?php echo $v['named'];?></td>
        <td><?php echo $v['title'];?></td>
        <td><?php echo $v['type'];?></td>
        <td><?php echo $v['price'];?></td>
        <td><a href="a.php?id=<?php echo $v['id'];?>"><span class="label label-info">修改</span></a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="b.php?id=<?php echo $v['id'];?>"><span class="label label-danger">删除</span></a></td>
    </tr>
    </tbody>
    <?php } ?>
</table>
